package com.example.leetcode.prcatice;

import java.util.HashSet;
import java.util.Set;

public class WordDictionary {

    private final Set<String> set;

    public WordDictionary() {
        set = new HashSet<>();
    }

    public void addWord(String word) {
        set.add(word);
    }

    public boolean search(String word) {
        if (set.contains(word)) {
            return true;
        }
        for (String s : set) {
            boolean b = compareToString(word, s);
            if (b) {
                return true;
            }
        }
        return false;
    }

    public boolean compareToString(String word,String word1){
        if (word.length() != word1.length()){
            return false;
        }
        int size = word.length();
        for(int i =0;i<size;i++){
            if (word.charAt(i) == '.'){
                continue;
            }else {
                if (word.charAt(i) != word1.charAt(i)){
                    return false;
                }
            }
        }
        return true;
    }
}
